package edu.stu.cs.software.family.warehouse.service.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import edu.stu.cs.software.family.base.service.impl.GenericManagerImpl;
import edu.stu.cs.software.family.warehouse.dao.ProductDao;
import edu.stu.cs.software.family.warehouse.domain.Product;
import edu.stu.cs.software.family.warehouse.service.ProductManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;

@Component
public class ProductManagerImpl extends GenericManagerImpl<Product, Long> implements ProductManager {

	ProductDao productDao;
	@Override
	public List<Product> findByName(String name) {
		
		Product queryObject =new Product();
		queryObject.setCode(name);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("name", GenericPropertyMatchers.startsWith());
		Example<Product> ex = Example.of(queryObject, matcher);
		List<Product> result =this.productDao.findAll(ex);
		return result;
	}

	@Override
	public List<Product> findByCode(String code) {
		
		Product queryObject =new Product();
		queryObject.setCode(code);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("qq", GenericPropertyMatchers.startsWith());
		Example<Product> ex = Example.of(queryObject, matcher);
		List<Product> result =this.productDao.findAll(ex);
		return result;
	}

	@Autowired
	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
		this.dao=productDao;
	}
	
	
	
}
